package com.john.blog.service.impl;

import java.util.List;

import javax.annotation.PostConstruct;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.john.blog.common.utils.DetectUtils;
import com.john.blog.model.mapper.UserMapper;
import com.john.blog.model.po.Model;
import com.john.blog.model.po.User;
import com.john.blog.service.UserService;

import tk.mybatis.mapper.entity.Example;

/**
 * 友情连接服务
 * 
 * @author JiangGengchao
 * @date 2018年2月4日
 */
@Service("userService")
public class UserServiceImpl extends BaseServiceImpl<User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @PostConstruct
    public void init() {
        this.mapper = userMapper;
    }

    @Override
    public User selectByPrimaryKey(String id) {
        Example example = new Example(User.class);
        example.createCriteria().andEqualTo(Model.ID, id);
        List<User> result = this.selectByExample(example);
        if (DetectUtils.notEmpty(result)) {
            return result.get(0);
        } else {
            return null;
        }
    }

    @Override
    public User updateByPrimaryKeySelective(User record) {
        this.mapper.updateByPrimaryKeySelective(record);
        return this.selectByPrimaryKey(record.getId());
    }

}
